<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_fiche_evaluation=new fiche_evaluation();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["code_fiche"])){$_fiche_evaluation->set_code_fiche($_POST["code_fiche"]);}
		if(isset($_POST["code_depot"])){$_fiche_evaluation->set_code_depot($_POST["code_depot"]);}
		if(isset($_POST["CIN"])){$_fiche_evaluation->set_CIN($_POST["CIN"]);}
		if(isset($_POST["date_envoi_eval"])){$_fiche_evaluation->set_date_envoi_eval($_POST["date_envoi_eval"]);}
		if(isset($_POST["daye_reception_rapport"])){$_fiche_evaluation->set_daye_reception_rapport($_POST["daye_reception_rapport"]);}
		if(isset($_POST["date_RE_concepteur"])){$_fiche_evaluation->set_date_RE_concepteur($_POST["date_RE_concepteur"]);}
		if(isset($_POST["observation"])){$_fiche_evaluation->set_observation($_POST["observation"]);}
		if(isset($_POST["decision"])){$_fiche_evaluation->set_decision($_POST["decision"]);}
		$res=$_fiche_evaluation->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["code_fiche"])){
		$_fiche_evaluation->set_code_fiche($_POST["code_fiche"]);
		$res=$_fiche_evaluation->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["code_fiche"])){$_fiche_evaluation->set_code_fiche($_POST["code_fiche"]);}
		if(isset($_POST["code_depot"])){$_fiche_evaluation->set_code_depot($_POST["code_depot"]);}
		if(isset($_POST["CIN"])){$_fiche_evaluation->set_CIN($_POST["CIN"]);}
		if(isset($_POST["date_envoi_eval"])){$_fiche_evaluation->set_date_envoi_eval($_POST["date_envoi_eval"]);}
		if(isset($_POST["daye_reception_rapport"])){$_fiche_evaluation->set_daye_reception_rapport($_POST["daye_reception_rapport"]);}
		if(isset($_POST["date_RE_concepteur"])){$_fiche_evaluation->set_date_RE_concepteur($_POST["date_RE_concepteur"]);}
		if(isset($_POST["observation"])){$_fiche_evaluation->set_observation($_POST["observation"]);}
		if(isset($_POST["decision"])){$_fiche_evaluation->set_decision($_POST["decision"]);}
		$res=$_fiche_evaluation->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["code_fiche"]) && !empty($_POST["code_fiche"])){
		$constraint.=" AND code_fiche='".$_POST["code_fiche"]."'";
	}

	if(isset($_POST["code_depot"]) && !empty($_POST["code_depot"])){
		$constraint.=" AND code_depot='".$_POST["code_depot"]."'";
	}

	if(isset($_POST["CIN"]) && !empty($_POST["CIN"])){
		$constraint.=" AND CIN='".$_POST["CIN"]."'";
	}

	if(isset($_POST["date_envoi_eval"]) && !empty($_POST["date_envoi_eval"])){
		$constraint.=" AND date_envoi_eval='".$_POST["date_envoi_eval"]."'";
	}

	if(isset($_POST["daye_reception_rapport"]) && !empty($_POST["daye_reception_rapport"])){
		$constraint.=" AND daye_reception_rapport='".$_POST["daye_reception_rapport"]."'";
	}

	if(isset($_POST["date_RE_concepteur"]) && !empty($_POST["date_RE_concepteur"])){
		$constraint.=" AND date_RE_concepteur='".$_POST["date_RE_concepteur"]."'";
	}

	if(isset($_POST["observation"]) && !empty($_POST["observation"])){
		$constraint.=" AND observation='".$_POST["observation"]."'";
	}

	if(isset($_POST["decision"]) && !empty($_POST["decision"])){
		$constraint.=" AND decision='".$_POST["decision"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_fiche_evaluation->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_fiche_evaluation->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>